import React, { Component } from 'react'
import './index.css'
import { Input,Form,Button,Upload} from 'element-react';
import axios from 'axios';

export default class PersonalAdd extends Component {
  constructor(props) {
  super(props);

  this.state = {
    labelPosition: 'right',
    PersonalInfo: {
      name: '',
      age:'',
      sex:'',
      phone:'',
      stuID: '',
      personalID:'',
      college:'',
      status:'',
      personalimg:'',
      fileList: "",
      honor :"",
      punishment:""
    }
  };
}
onPositionChange(value) {
  this.setState({ labelPosition: value });
}

onChange(key, value) {
  this.setState({
    form: Object.assign(this.state.PersonalInfo, { [key]: value })
  });
}

HandleBackPersonal = () =>{
  let history = this.props.history;
  history.push('/PersonalList')
}


HandleAddPersonal = () =>{
  axios.post('/Sidebar/PersonalAdd/user/addUser',this.state.PersonalInfo).then((response)=>{
    let data = response.data
    console.log(data)
    if(data.status === 200){
      this.setState.PersonalInfo = {};
      alert('添加成功')
    }
    else{
      this.setState.PersonalInfo = {};
      alert("添加失败")
    }
  })
}


  render() {
    return (
      <div className='PersonalFiles'>
        <div className='BackgroundPage'>
          <img className='shoollogo' src={require('./img/logo-w.png')} alt="es-lint want to get"/>
          <div className='PersonalInfo'>
          <Form labelPosition={this.state.labelPosition} labelWidth="100" model={this.state.PersonalInfo} className="demo-form-stacked">
          <div className="personalImg">
          </div>  
        <Form.Item label="姓名" className='personalName'>
          <Input className='button_control' value={this.state.PersonalInfo.name} onChange={this.onChange.bind(this, 'name')}></Input>
        </Form.Item>
        <Form.Item label="性别" className='personalSex'>
          <Input className='button_control' value={this.state.PersonalInfo.sex} onChange={this.onChange.bind(this, 'sex')}></Input>
        </Form.Item>
        <Form.Item label="年龄" className='personalage'>
          <Input className='button_control' value={this.state.PersonalInfo.age} onChange={this.onChange.bind(this, 'age')}></Input>
        </Form.Item>
        <Form.Item label="身份证号" className='personalID'>
          <Input className='button_control' value={this.state.PersonalInfo.personalID} onChange={this.onChange.bind(this, 'personalID')}></Input>
        </Form.Item>
        <Form.Item label="学号/教工号" className='personalschoolID'>
          <Input className='button_control' value={this.state.PersonalInfo.stuID} onChange={this.onChange.bind(this, 'stuID')}></Input>
        </Form.Item>
        <Form.Item label="电话" className='personalPhone'>
          <Input className='button_control' value={this.state.PersonalInfo.phone} onChange={this.onChange.bind(this, 'phone')}></Input>
        </Form.Item>
        <Form.Item label="学院" className='personalCollege'>
          <Input className='button_control' value={this.state.PersonalInfo.college} onChange={this.onChange.bind(this, 'college')}></Input>
        </Form.Item>
        <Form.Item label="身份" className='personalStatus'>
          <Input className='button_control' value={this.state.PersonalInfo.status} onChange={this.onChange.bind(this, 'status')}></Input>
        </Form.Item>
        <Form.Item label="嘉奖经历" className='personalHonor'>
          <Input className='button_control' value={this.state.PersonalInfo.honor} onChange={this.onChange.bind(this, 'honor')}></Input>
        </Form.Item>
        <Form.Item label="惩处经历" className='personalPunishment'>
          <Input className='button_control' value={this.state.PersonalInfo.punishment} onChange={this.onChange.bind(this, 'punishment')}></Input>
        </Form.Item>
        <Button type="success" className='back_button' onClick={this.HandleBackPersonal}>返回</Button>
        <Button type="info" className='edit_button' onClick={this.HandleAddPersonal}>提交</Button>
        </Form>
        </div>
        </div>
      </div>
    )
  }
}
